Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli keeps calling non paginated endpoint even when interactive flag is on #847

Merged
merged 8 commits into from
Nov 2, 2022

Conversation

ajayy004
Copy link
Contributor

@ajayy004 ajayy004 commented Oct 31, 2022

Description

Issue: CLI makes a workspace list query to identify if there is 1 or more workspace

Fix: If the interactive flag is set to true, CLI will call the paginated workspace query with page size 2 to make the same decision to auto-select the first workspace if it returns 1 record if it returns more than 1. The user will be prompted to select a workspace

Enhancement: Added new query to validate workspaceId, which does not pull roleBindings since it's not required to validate workspaceId.

🎟 Issue(s)

Related https://github.com/astronomer/issues/issues/5166

🧪 Functional Testing

List the functional testing steps to confirm this feature or fix.

📸 Screenshots

with-interactive-flag-set-to-true
with-interactive-flag-set-to-true

with-interactive-flag-set-to-false
with-interactive-flag-set-to-false

📋 Checklist

  • Rebased from the main (or release if patching) branch (before testing)
  • Ran make test before taking out of draft
  • Ran make lint before taking out of draft
  • Added/updated applicable tests
  • Tested against Astro-API (if necessary).
  • Tested against Houston-API and Astronomer (if necessary).
  • Communicated to/tagged owners of respective clients potentially impacted by these changes.
  • Updated any related documentation

software/auth/auth.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Oct 31, 2022

Codecov Report

Base: 87.05% // Head: 87.06% // Increases project coverage by +0.00% 🎉

Coverage data is based on head (807b40f) compared to base (8e0445e).
Patch coverage: 93.75% of modified lines in pull request are covered.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #847   +/-   ##
=======================================
  Coverage   87.05%   87.06%           
=======================================
  Files         100      100           
  Lines        8652     8674   +22     
=======================================
+ Hits         7532     7552   +20     
- Misses        653      654    +1     
- Partials      467      468    +1     
Impacted Files Coverage Δ
houston/houston.go 78.43% <ø> (ø)
houston/workspace.go 93.44% <81.81%> (-2.56%) ⬇️
software/auth/auth.go 81.87% <100.00%> (+1.44%) ⬆️
software/workspace/workspace.go 93.05% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ajayy004 ajayy004 marked this pull request as ready for review October 31, 2022 21:10
var err error

if interactive {
workspacePageSize := 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use the PageSize value from config.CFG.PageSize or else defaultPageSize?
Reference: https://github.com/astronomer/astro-cli/blob/main/software/auth/auth.go#L135

Copy link
Contributor Author

@ajayy004 ajayy004 Nov 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we need to identify if the number of workspaces returned 1 or more, calling workspace pagination with page size 2 if the interactive flag is set to true, pulling 100 records does not make sense as we just need to make a decision of 1 or more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not entirely true, because the list of workspaces returned from this method is used to switch to last_used_workspace, and by just pulling two workspaces, that functionality will almost always be broken in case interactive is set to true.

So from a UX point of view, if interactive is set to true, then whenever a user tries to log in, they would be asked to select a particular workspace every single time, and not automatically set the last used workspace from the previous login as the current workspace.

We should document this in our release note if we are going with this approach, and also add comments in the code around the logic of choosing the page size as 2 for future reference.

Might want to check once on this functional change with @cmarteepants if not already done.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The trade-off (selecting the workspace every single time a user logs in) is too expensive from a UX standpoint. I'm not following how the change helps solve the initial problem. Is there another approach we can use to solve the problem, while retaining the login UX?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, I'll change the implementation of switchToLastUsedWorkspace to use getWorkspace API to identify if the user still has access/available last_used_workspace workspace. That way will have the same user experience.

…ad of looping through workspaces

* added get workspace query without rolebinding to validate workspace id
… roleBindings since its not used to validate workspaceId
@ajayy004 ajayy004 requested a review from neel-astro November 1, 2022 18:33
Copy link
Contributor

@neel-astro neel-astro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, have left in a minor nitpick

software/auth/auth.go Show resolved Hide resolved
…dentify user has access to more than 1 workspace access
@neel-astro neel-astro merged commit f500517 into main Nov 2, 2022
@neel-astro neel-astro deleted the bugfix/5166 branch November 2, 2022 15:51
neel-astro pushed a commit that referenced this pull request Nov 2, 2022
…s on (#847)

* call workspace pagination query when interactive flag set to true

* fixed lint issue

* * changed switchToLastUsedWorkspace function to query workspace instead of looping through workspaces
* added get workspace query without rolebinding to validate workspace id

* replaced getWorkspace query with ValidateWorkspaceId to avoid pulling roleBindings since its not used to validate workspaceId

* fixed lint issue

* added test coverage for ValidateWorkspaceID

* added test coverage for switchToLastUsedWorkspace

* added comment, why we need call with certain workspace page size to identify user has access to more than 1 workspace access
neel-astro pushed a commit that referenced this pull request Nov 2, 2022
…s on (#847)

* call workspace pagination query when interactive flag set to true

* fixed lint issue

* * changed switchToLastUsedWorkspace function to query workspace instead of looping through workspaces
* added get workspace query without rolebinding to validate workspace id

* replaced getWorkspace query with ValidateWorkspaceId to avoid pulling roleBindings since its not used to validate workspaceId

* fixed lint issue

* added test coverage for ValidateWorkspaceID

* added test coverage for switchToLastUsedWorkspace

* added comment, why we need call with certain workspace page size to identify user has access to more than 1 workspace access
jemishp pushed a commit that referenced this pull request Nov 2, 2022
…s on (#847)

* call workspace pagination query when interactive flag set to true

* fixed lint issue

* * changed switchToLastUsedWorkspace function to query workspace instead of looping through workspaces
* added get workspace query without rolebinding to validate workspace id

* replaced getWorkspace query with ValidateWorkspaceId to avoid pulling roleBindings since its not used to validate workspaceId

* fixed lint issue

* added test coverage for ValidateWorkspaceID

* added test coverage for switchToLastUsedWorkspace

* added comment, why we need call with certain workspace page size to identify user has access to more than 1 workspace access
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants